package cn.itcast.mq.listener;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalTime;

@Component
public class SpringRabbitListener {

//    @RabbitListener(queues = "simple.queue")
//    public void listenSimpleQueue(String msg) {
//        System.out.println("接收到消息【" + msg + "】");
//    }

    @RabbitListener(queues = "simple.queue")
    public void listenWorkQueue1(String msg) throws InterruptedException {
        System.out.println("queue 1 接收到消息【" + msg + "】" + "  " + LocalTime.now());
        Thread.sleep(20);
    }

    @RabbitListener(queues = "simple.queue")
    public void listenWorkQueue2(String msg) throws InterruptedException {
        System.err.println("queue 2 接收到消息【" + msg + "】" + " " + LocalTime.now());
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void ListenFanoutQueue1(String msg) {
        System.out.println("fanout.queue1接收到消息【" + msg + "】");
    }

    @RabbitListener(queues = "fanout.queue2")
    public void ListenFanoutQueue2(String msg) {
        System.out.println("fanout.queue2接收到消息【" + msg + "】");
    }
}
